import requests
from lxml import etree
import os
try:
    for j in range(1,5):
        os.mkdir("f:\\python\\summer\\zez{}".format(j))
        response = requests.get("https://alpha.wallhaven.cc/search?q=&categories=001&purity=100&topRange=1M&sorting=toplist&order=desc&page={}".format(j))

        response.encoding = "utf-8"
        selector = etree.HTML(response.text)
        img = selector.xpath('//img/@data-src')
        for i in range(0,len(img)):
            img[i]
            print(img[i])
            response = requests.get (img[i])
            try:
               with open("f:\\python\\summer\\zez{}\\page{}_imgimg{}.jpg".format(j,j,i),"wb+") as f:
                f.write(response.content)
            except:
                print("网页访问有问题，请检查代码和网络")
except:
        print("网页访问有问题，请检查代码和网络")